// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <melon/socket_address.h>
#include <pollux/expression/vector_function.h>
#include <pollux/functions/remote/if/gen-cpp2/RemoteFunction_types.h>

namespace kumo::pollux::functions {
    struct RemoteVectorFunctionMetadata : public exec::VectorFunctionMetadata {
        /// Network address of the servr to communicate with. Note that this can hold
        /// a network location (ip/port pair) or a unix domain socket path (see
        /// SocketAddress::makeFromPath()).
        melon::SocketAddress location;

        /// The serialization format to be used
        remote::PageFormat serdeFormat{remote::PageFormat::PRESTO_PAGE};
    };

    /// Registers a new remote function. It will use the meatadata defined in
    /// `RemoteVectorFunctionMetadata` to control the serialization format and
    /// remote server address.
    //
    /// Remote functions are registered as regular statufull functions (using the
    /// same internal catalog), and hence conflict if there already exists a
    /// (non-remote) function registered with the same name. The `overwrite` flag
    /// controls whether to overwrite in these cases.
    void registerRemoteFunction(
        const std::string &name,
        std::vector<exec::FunctionSignaturePtr> signatures,
        const RemoteVectorFunctionMetadata &metadata = {},
        bool overwrite = true);
} // namespace kumo::pollux::functions
